﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Consult
{
    public partial class ConsultForm_Type_Option : BaseForm
    {
        ServiceConsult service = new ServiceConsult();
        TB_ConsultType model = null;
        private string strDataID = string.Empty;
        public ConsultForm_Type_Option(string strdataid)
        {
            InitializeComponent();
            strDataID = strdataid;
            if (strDataID.Length > 0)
            {
                BindModel();
            }
        }

        private void BindModel()
        {
            model = service.GetDicMsgTypeModel(strDataID);
            if (model != null)
            {
                txtConsultCount.Text = model.ConsultCount.ToSafeString();
                txtName.Text = model.TypeName;
                txtTypeTags.Text = model.TypeTags.ToSafeString();
                txtSort.Text = model.Sort.ToSafeString();
                if (model.State == "1")
                {
                    chkSFKF.Checked = true;
                }
                else
                {
                    chkSFKF.Checked = false;
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请输入名称！");
                txtName.Focus();
                return;
            }
            if (model == null)
            {
                model = new TB_ConsultType();
            }
            else
            {
                model.Attach();
            }
            model.ConsultCount = txtConsultCount.Text.ToSafeInt();
            model.CreateDate = DateTime.Now;
            model.CreateUser = SessionerHelper.LoginName;
            model.Sort = txtSort.Text.ToSafeInt();
            if (chkSFKF.Checked)
            {
                model.State = "1";
            }
            else
            {
                model.State = "0";
            }
            model.TypeName = txtName.Text;
            model.TypeTags = txtTypeTags.Text.ToSafeInt();
            service.SaveDicMsgType(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
